//
//  DestinationCollectionViewCell.m
//  HappyTrip
//
//  Created by yuxuesong on 15-3-23.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DestinationCollectionViewCell.h"

//@interface DestinationCollectionViewCell()
//
//@property (nonatomic, retain)UIImageView *destinationImageView;
//@property (nonatomic, retain)UILabel *destinationNameLabel;
//
//@end

@implementation DestinationCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.destinationImageView = [[UIImageView alloc] init];
        self.destinationImageView.clipsToBounds = YES;
        [self.contentView addSubview:self.destinationImageView];
        [_destinationImageView release];
        
        self.destinationNameLabel = [[UILabel alloc] init];
        self.destinationNameLabel.backgroundColor = [UIColor blackColor];
        self.destinationNameLabel.alpha = 0.5f;
        self.destinationNameLabel.textAlignment = NSTextAlignmentCenter;
        [self.destinationImageView addSubview:self.destinationNameLabel];
        [_destinationNameLabel release];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    CGFloat width = layoutAttributes.bounds.size.width;
    CGFloat height = layoutAttributes.bounds.size.height;
    self.destinationNameLabel.frame = CGRectMake(0, height * 5 / 6, width, height / 6);
    self.destinationNameLabel.textColor = [UIColor whiteColor];
    self.destinationImageView.frame = CGRectMake(0, 0, width, height);
    self.destinationImageView.layer.cornerRadius = width / 15;
}


- (void)setDetailObject:(DestinationDetailObject *)detailObject
{
    if (_detailObject != detailObject) {
        [_detailObject release];
        _detailObject = [detailObject retain];
    }
    [self.destinationImageView setImageWithURL:[NSURL URLWithString:_detailObject.cover_s] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    self.destinationNameLabel.text = self.detailObject.name;
}



- (void)dealloc
{
    [_detailObject release];
    [_destinationNameLabel release];
    [_destinationImageView release];
    [super dealloc];
}

@end
